import { BreadcrumbProps, PopconfirmProps, TabsProps, DropdownProps, MenuProps } from 'antd'
import { useState } from 'react'
import { useLocation } from './query';
import type { DropdownButtonProps } from 'antd/es/dropdown';

export function useDropdownButton(menu: MenuProps) {
    const props: DropdownButtonProps = {
        menu: menu,
    }
    return {
        props
    }
}

export function useTabs(items: TabsProps['items'], def: string = 'list') {
    const location = useLocation();
    const action = location.searchParams.get('tab') || def;
    const [activeKey, setActiveKey] = useState<string>(action);
    const props: TabsProps = {
        activeKey,
        onChange: setActiveKey,
        items: items
    }
    return {
        props,
        activeKey
    }
}

export function usePopconfirm(title: string, description?: string) {
    const props: PopconfirmProps = {
        title,
        description,
        onCancel: () => { },
        onConfirm: () => { },
        okText: '确定',
        cancelText: '取消'
    }
    return {
        props
    }
}

export function useBreadcrumb() {
    const [items, setItems] = useState<BreadcrumbProps['items']>([])
    const props: BreadcrumbProps = {
        items: items
    }
    return {
        props,
        setItems
    }
}

